//
//  CMGetUserInfoManager.m
//  CreditManger
//
//  Created by chaiyanan on 15/11/5.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "CMGetUserInfoManager.h"
#import "CMGetUserInfoParam.h"
#import "CMGetUserInfoParser.h"
#import "CMLoginManager.h"

@implementation CMGetUserInfoManager

+ (void)requestToGetUserInfoWithResult:(void (^)(BOOL, NSString *, NSError *))result
{
    CMGetUserInfoParam *param = [[CMGetUserInfoParam alloc]init];
    param.uid = [CMLoginManager sharedCMLoginManager].currentUserInfo.uid;
    param.token = [CMLoginManager sharedCMLoginManager].currentUserInfo.token;
    CMGetUserInfoParser *parser = [[CMGetUserInfoParser alloc]init];
    [NetCenter getDataFromURL:Method_getUserInfo
                        params:param
                        parser:parser
                        result:^(ParserResult *myResult)
     {
         if (myResult.code ==0 )
         {
             CMLoginUserInfo *info = (CMLoginUserInfo *)myResult.result;
             info.token = [CMLoginManager sharedCMLoginManager].currentUserInfo.token;
             [CMLoginManager cacheCurrentUserToUserDefault:info];
             if (result)
             {
                 result(YES, @"", nil);
             }
         }
         else
         {
             if (result)
             {
                 result(NO, myResult.message, nil);
             }
         }
         
     } failure:^(NSError *error)
     {
         if (result)
         {
             result(NO, @"", error);
         }
     }];
    
}

@end
